#include "common.h"
#include "tests.h"
#include "date.h"
#include <string.h>

#define TEST_BUFFER_LOCAL_TIME_LENGTH 1024

int init_test_suite_date_time(void)
{
    return(DATE_Init() ? 0 : 1);
}

int cleanup_test_suite_date_time(void)
{
    DATE_Free();
    return 0;
}

void test_date_time_convert()
{
	//we expect date and time information inside a string to be converted into struct tm type.
	CU_ASSERT(DATE_ConvertLocalTime("Mon, 24 Sep 2012 12:01:32 GMT"));
}

void test_date_time_extract()
{
	char test_buffer_localtime[TEST_BUFFER_LOCAL_TIME_LENGTH];
	//we expect buffer_localtime to include time string with local timezone
	if(DATE_ExtractLocalTime("GMT-4", test_buffer_localtime, TEST_BUFFER_LOCAL_TIME_LENGTH))
	{
	    CU_ASSERT_STRING_EQUAL(test_buffer_localtime, "Mon Sep 24 08:01:32 2012 GMT-4");
	}
	else
	{
		CU_ASSERT(false);
	}
   
}

void add_test_suite_date_time()
{
	CU_pSuite pSuite = NULL;

    /* add a suite to the registry */
    pSuite = CU_add_suite("Date-time conversion test suite", init_test_suite_date_time, cleanup_test_suite_date_time);
    if (NULL == pSuite) {
        print_last_error();
        return;
    }

	 /* add the tests to the suite */
    if ((NULL == CU_ADD_TEST(pSuite, test_date_time_convert)) ||
		(NULL == CU_ADD_TEST(pSuite, test_date_time_extract)))
    {
        print_last_error();
        return;
    }
}